package com.chauncy.DMS.servlet;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sun.java2d.pipe.BufferedBufImgOps;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.chauncy.DMS.dao.ManagerDaoImplement;

public class UpdataAloneAttInfoServlet extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			ManagerDaoImplement daoImplement = new ManagerDaoImplement();
			JSONObject object = null;
			int attId = 0;
			String sNumber= "null";
			int qingjia = 0;
			String qingjiaTime = "null";
			int wangui = 0;
			String wanguiTime = "null";
			int weigui = 0;
			String attTime = "null";
			String remarks = "null";
			if(request.getParameter("attData") !=null && !request.getParameter("attData").equals("")){
				JSONArray attDataObject = JSONArray.fromObject(request.getParameter("attData"));
				object = (JSONObject) attDataObject.get(0);
				//考勤录入 获取修改的值
				attId = Integer.parseInt( String.valueOf( object.get("AttId")));
				sNumber = (String)object.get("sNumber");
				qingjia =Integer.parseInt( String.valueOf( object.get("qingjia")));		
				qingjiaTime =  String.valueOf(object.get("qingjiaTime"));
				if(qingjiaTime == null){
					qingjiaTime = "is null";
				}
				System.out.println(qingjiaTime +"//11");
				wangui =Integer.parseInt( String.valueOf( object.get("wangui")));
				wanguiTime = String.valueOf(object.get("wanguiTime"));		
				if(wanguiTime == null || wanguiTime.equals("")){
					wanguiTime = "is null";
				}
				System.out.println(wanguiTime + "//22");
				remarks = String.valueOf(object.get("remarks"));
				if(remarks == null || remarks.equals("")){
					remarks = "is null";
				}
				System.out.println(remarks +"//33");
				weigui = Integer.parseInt( String.valueOf( object.get("weigui")));
			
			}else{
				//查询单挑记录 修改的值
				object =  JSONObject.fromObject( request.getParameter("obj"));
				attId =Integer.parseInt(String.valueOf( object.get("AttId")));
				sNumber = String.valueOf(object.get("sNumber"));
				qingjia =Integer.parseInt( String.valueOf(object.get("qingjia")));
				qingjiaTime =  String.valueOf(object.get("qingjiaTime"));
				wangui =Integer.parseInt( String.valueOf(object.get("wangui")));
				wanguiTime = String.valueOf(object.get("wanguiTime"));
				remarks = String.valueOf(object.get("remarks"));
				weigui = Integer.parseInt( String.valueOf(object.get("weigui")));
			}
		
			//获取ajax 传递值，将其转换成JSON
	
			String sql = "CALL AttInfoUpdata(?,?,?,?,?,?,?);";
			Object[] param = {qingjia,qingjiaTime,wangui,wanguiTime,weigui,remarks,attId};
			//更新学生考勤信息 
			int flag = daoImplement.updata(sql, param);
			request.setAttribute("obj", object);
			response.getWriter().print(flag);
	}
}
